# Maintainer: Jonas Witschel <diabonas@archlinux.org>
pkgname=python-tpm2-pytss
pkgver=2.1.0
_commit=d4cccb9e1164281455a3c05f4aab2e663133726b  # refs/tags/2.1.0
pkgrel=1
pkgdesc='Python bindings for tpm2-tss'
arch=('loong64' 'x86_64')
url='https://github.com/tpm2-software/tpm2-pytss'
license=('BSD')
depends=('glibc' 'python' 'python-asn1crypto' 'python-cffi' 'python-cryptography' 'python-packaging' 'python-yaml'
         'tpm2-tss' 'libtss2-esys.so' 'libtss2-fapi.so' 'libtss2-mu.so' 'libtss2-rc.so' 'libtss2-tctildr.so')
makedepends=('git' 'python-build' 'python-installer' 'python-pkgconfig'
             'python-setuptools' 'python-setuptools-scm' 'python-wheel')
checkdepends=('python-pytest' 'swtpm' 'tpm2-tools')
source=("git+$url.git#tag=$_commit?signed")
sha512sums=('SKIP')
validpgpkeys=('5B482B8E3E19DA7C978E1D016DE2E9078E1F50C1') # William Roberts (Bill Roberts) <william.c.roberts@intel.com>

pkgver() {
	cd "${pkgname#python-}"
	git describe | sed 's/\([^-]*-\)g/r\1/;s/-/./g'
}

build() {
	cd "${pkgname#python-}"
	python -m build --wheel --no-isolation
}

check() {
	cd "${pkgname#python-}"
	local _python_version=$(python -c 'import sys; print("".join(map(str, sys.version_info[:2])))')
	PYTHONPATH="$PWD/build/lib.linux-$CARCH-cpython-$_python_version" pytest
}

package() {
	cd "${pkgname#python-}"
	python -m installer --destdir="$pkgdir" dist/*.whl
	install -Dm644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname"
}
